package pl.ericpol.kernel.schemas;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import pl.ericpol.commons.Sign;
import pl.ericpol.environment.devices.Device;
import pl.ericpol.environment.sensors.Sensor;
import pl.ericpol.stubs.LampAdapterStub;
import pl.ericpol.stubs.LightSensorAdapterStub;
import pl.ericpol.stubs.MoveSensorAdapterStub;

public class FileSchemaBuilder extends SchemaBuilder {

	private static Logger logger = LogManager.getLogger(LampAdapterStub.class);
	private byte defaultPriority = 1;

		
	@Override
	public Schema createSchema(String filepath, String name) {
		return fileStub(filepath, name);
	}
	
	/**
	 * Time stab for file parsing and configure schema.
	 * 
	 * @param filepath
	 */
	public Schema fileStub(String filepath,String name) {
		//schema = new Schema();	
		Schema schema = new GeneralSchema();
		
		Device lamp1 = new LampAdapterStub(1);
		Device lamp2 = new LampAdapterStub(2);
		Device lamp3 = new LampAdapterStub(3);
		
		Sensor moveSensor1 = new MoveSensorAdapterStub(1);
		Sensor moveSensor2 = new MoveSensorAdapterStub(2);
		Sensor lightSensor1 = new LightSensorAdapterStub(1);
		
		Map<Device, Integer> devices1 = new HashMap<Device, Integer>();
		devices1.put(lamp1, 50);
		devices1.put(lamp2, 10);
		
		Map<Device, Integer> devices2 = new HashMap<Device, Integer>();
		devices2.put(lamp3, 100);
		
		Map<Sensor, Object[]> sensors1 = new HashMap<Sensor, Object[]>();
		Object ob1[]={Sign.E, 1L};
		Object ob2[]={Sign.E, 0L};
		Object ob3[]={Sign.G, 50L};
		
		sensors1.put(moveSensor1, ob1);
		sensors1.put(moveSensor2, ob2);
		sensors1.put(lightSensor1, ob3);
		
		Map<Sensor, Object[]> sensors2 = new HashMap<Sensor, Object[]>();
		sensors2.put(moveSensor1, ob1);
		
		Condition condition1 = new Condition(devices1, sensors1, defaultPriority);
		Condition condition2 = new Condition(devices2, sensors1, defaultPriority);
		Condition condition3 = new Condition(devices1, sensors2, (byte)10);
		
		List<Condition> conditions = new ArrayList<Condition>();
		conditions.add(condition1);
		conditions.add(condition2);
		conditions.add(condition3);
		
		schema.setConditions(conditions);	
		
		logger.info("Schema was created");
		schema.setName(name);
		logger.info("create schema stub is fineshed");
		return schema;
		
	}

}
